package com.zhentao.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhentao.entity.product.Category;
import com.zhentao.entity.product.ProductSku;
import com.zhentao.service.CategoryService;
import com.zhentao.service.ProductService;
import com.zhentao.vo.common.Result;
import com.zhentao.vo.common.ResultCodeEnum;
import com.zhentao.vo.h5.IndexVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "首页接口管理")
@RestController
@RequestMapping(value="/api/product/index")
//@CrossOrigin
@SuppressWarnings({"unchecked", "rawtypes"})
public class IndexController {

   @Resource
   private CategoryService categoryService;

   @Resource
   private ProductService productService;

   /**
    * 获取首页数据
    * @return
    */
   @Operation(summary = "获取首页数据")
   @GetMapping
   public Result<IndexVo> findData(){
      List<Category> categoryList = categoryService.list(Wrappers.<Category>lambdaQuery().eq(Category::getIsDeleted,0).eq(Category::getParentId,0).eq(Category::getStatus,1));
      List<ProductSku> productSkuList = productService.findProductSkuBySale();
      IndexVo indexVo = new IndexVo() ;
      indexVo.setCategoryList(categoryList);
      indexVo.setProductSkuList(productSkuList);
      return Result.build(indexVo , ResultCodeEnum.SUCCESS);
   }

}